﻿/**  版本信息模板在安装目录下，可自行修改。
* hars_appointmentrecord.cs
*
* 功 能： N/A
* 类 名： hars_appointmentrecord
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2017/9/16 11:32:16   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;

namespace PreeRegisterDAL
{
    /// <summary>
    /// 数据访问类:hars_appointmentrecord
    /// </summary>
    public partial class hars_appointmentrecord
    {
        public hars_appointmentrecord()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperMySQL.GetMaxID("id", "hars_appointmentrecord");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from hars_appointmentrecord");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            return DbHelperMySQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(PreeRegisterModel.hars_appointmentrecord model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into hars_appointmentrecord(");
            strSql.Append("mtype,state,name,tel,card,gender,addr,birth,ctype,cid,ptype,rtype,deptid,deptname,doctorid,doctorname,wid,iid,inum,oid,ofee,price,price2,cout,dcount,tdate,isdelete,createdate,lastdate,orderid)");
            strSql.Append(" values (");
            strSql.Append("@mtype,@state,@name,@tel,@card,@gender,@addr,@birth,@ctype,@cid,@ptype,@rtype,@deptid,@deptname,@doctorid,@doctorname,@wid,@iid,@inum,@oid,@ofee,@price,@price2,@cout,@dcount,@tdate,@isdelete,@createdate,@lastdate,@orderid)");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@mtype", MySqlDbType.Int32,2),
                    new MySqlParameter("@state", MySqlDbType.Int32,2),
                    new MySqlParameter("@name", MySqlDbType.VarChar,200),
                    new MySqlParameter("@tel", MySqlDbType.VarChar,20),
                    new MySqlParameter("@card", MySqlDbType.VarChar,20),
                    new MySqlParameter("@gender", MySqlDbType.Int32,2),
                    new MySqlParameter("@addr", MySqlDbType.VarChar,200),
                    new MySqlParameter("@birth", MySqlDbType.VarChar,50),
                    new MySqlParameter("@ctype", MySqlDbType.Int32,2),
                    new MySqlParameter("@cid", MySqlDbType.VarChar,50),
                    new MySqlParameter("@ptype", MySqlDbType.Int32,2),
                    new MySqlParameter("@rtype", MySqlDbType.Int32,2),
                    new MySqlParameter("@deptid", MySqlDbType.VarChar,100),
                    new MySqlParameter("@deptname", MySqlDbType.VarChar,200),
                    new MySqlParameter("@doctorid", MySqlDbType.VarChar,100),
                    new MySqlParameter("@doctorname", MySqlDbType.VarChar,200),
                    new MySqlParameter("@wid", MySqlDbType.VarChar,200),
                    new MySqlParameter("@iid", MySqlDbType.VarChar,200),
                    new MySqlParameter("@inum", MySqlDbType.VarChar,20),
                    new MySqlParameter("@oid", MySqlDbType.VarChar,50),
                    new MySqlParameter("@ofee", MySqlDbType.Int32,5),
                    new MySqlParameter("@price", MySqlDbType.Int32,5),
                    new MySqlParameter("@price2", MySqlDbType.Int32,5),
                    new MySqlParameter("@cout", MySqlDbType.Int32,5),
                    new MySqlParameter("@dcount", MySqlDbType.Int32,5),
                    new MySqlParameter("@tdate", MySqlDbType.VarChar,20),
                    new MySqlParameter("@isdelete", MySqlDbType.Int32,2),
                    new MySqlParameter("@createdate", MySqlDbType.Timestamp),
                    new MySqlParameter("@lastdate", MySqlDbType.Timestamp),
                    new MySqlParameter("@orderid", MySqlDbType.VarChar,50)};
            parameters[0].Value = model.mtype;
            parameters[1].Value = model.state;
            parameters[2].Value = model.name;
            parameters[3].Value = model.tel;
            parameters[4].Value = model.card;
            parameters[5].Value = model.gender;
            parameters[6].Value = model.addr;
            parameters[7].Value = model.birth;
            parameters[8].Value = model.ctype;
            parameters[9].Value = model.cid;
            parameters[10].Value = model.ptype;
            parameters[11].Value = model.rtype;
            parameters[12].Value = model.deptid;
            parameters[13].Value = model.deptname;
            parameters[14].Value = model.doctorid;
            parameters[15].Value = model.doctorname;
            parameters[16].Value = model.wid;
            parameters[17].Value = model.iid;
            parameters[18].Value = model.inum;
            parameters[19].Value = model.oid;
            parameters[20].Value = model.ofee;
            parameters[21].Value = model.price;
            parameters[22].Value = model.price2;
            parameters[23].Value = model.cout;
            parameters[24].Value = model.dcount;
            parameters[25].Value = model.tdate;
            parameters[26].Value = model.isdelete;
            parameters[27].Value = model.createdate;
            parameters[28].Value = model.lastdate;
            parameters[29].Value = model.orderid;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PreeRegisterModel.hars_appointmentrecord model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update hars_appointmentrecord set ");
            strSql.Append("mtype=@mtype,");
            strSql.Append("name=@name,");
            strSql.Append("tel=@tel,");
            strSql.Append("card=@card,");
            strSql.Append("gender=@gender,");
            strSql.Append("addr=@addr,");
            strSql.Append("birth=@birth,");
            strSql.Append("ctype=@ctype,");
            strSql.Append("cid=@cid,");
            strSql.Append("ptype=@ptype,");
            strSql.Append("rtype=@rtype,");
            strSql.Append("deptid=@deptid,");
            strSql.Append("deptname=@deptname,");
            strSql.Append("doctorid=@doctorid,");
            strSql.Append("doctorname=@doctorname,");
            strSql.Append("wid=@wid,");
            strSql.Append("iid=@iid,");
            strSql.Append("inum=@inum,");
            strSql.Append("oid=@oid,");
            strSql.Append("ofee=@ofee,");
            strSql.Append("price=@price,");
            strSql.Append("price2=@price2,");
            strSql.Append("cout=@cout,");
            strSql.Append("dcount=@dcount,");
            strSql.Append("tdate=@tdate,");
            strSql.Append("isdelete=@isdelete");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@mtype", MySqlDbType.Int32,2),
                    new MySqlParameter("@name", MySqlDbType.VarChar,200),
                    new MySqlParameter("@tel", MySqlDbType.VarChar,20),
                    new MySqlParameter("@card", MySqlDbType.VarChar,20),
                    new MySqlParameter("@gender", MySqlDbType.Int32,2),
                    new MySqlParameter("@addr", MySqlDbType.VarChar,200),
                    new MySqlParameter("@birth", MySqlDbType.VarChar,50),
                    new MySqlParameter("@ctype", MySqlDbType.Int32,2),
                    new MySqlParameter("@cid", MySqlDbType.VarChar,50),
                    new MySqlParameter("@ptype", MySqlDbType.Int32,2),
                    new MySqlParameter("@rtype", MySqlDbType.Int32,2),
                    new MySqlParameter("@deptid", MySqlDbType.VarChar,20),
                    new MySqlParameter("@deptname", MySqlDbType.VarChar,50),
                    new MySqlParameter("@doctorid", MySqlDbType.VarChar,20),
                    new MySqlParameter("@doctorname", MySqlDbType.VarChar,20),
                    new MySqlParameter("@wid", MySqlDbType.VarChar,200),
                    new MySqlParameter("@iid", MySqlDbType.VarChar,200),
                    new MySqlParameter("@inum", MySqlDbType.VarChar,20),
                    new MySqlParameter("@oid", MySqlDbType.VarChar,50),
                    new MySqlParameter("@ofee", MySqlDbType.Int32,5),
                    new MySqlParameter("@price", MySqlDbType.Int32,5),
                    new MySqlParameter("@price2", MySqlDbType.Int32,5),
                    new MySqlParameter("@cout", MySqlDbType.Int32,5),
                    new MySqlParameter("@dcount", MySqlDbType.Int32,5),
                    new MySqlParameter("@tdate", MySqlDbType.VarChar,20),
                    new MySqlParameter("@isdelete", MySqlDbType.Int32,2),
                    new MySqlParameter("@id", MySqlDbType.Int32,50)};
            parameters[0].Value = model.mtype;
            parameters[1].Value = model.name;
            parameters[2].Value = model.tel;
            parameters[3].Value = model.card;
            parameters[4].Value = model.gender;
            parameters[5].Value = model.addr;
            parameters[6].Value = model.birth;
            parameters[7].Value = model.ctype;
            parameters[8].Value = model.cid;
            parameters[9].Value = model.ptype;
            parameters[10].Value = model.rtype;
            parameters[11].Value = model.deptid;
            parameters[12].Value = model.deptname;
            parameters[13].Value = model.doctorid;
            parameters[14].Value = model.doctorname;
            parameters[15].Value = model.wid;
            parameters[16].Value = model.iid;
            parameters[17].Value = model.inum;
            parameters[18].Value = model.oid;
            parameters[19].Value = model.ofee;
            parameters[20].Value = model.price;
            parameters[21].Value = model.price2;
            parameters[22].Value = model.cout;
            parameters[23].Value = model.dcount;
            parameters[24].Value = model.tdate;
            parameters[25].Value = model.isdelete;
            parameters[26].Value = model.id;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from hars_appointmentrecord ");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from hars_appointmentrecord ");
            strSql.Append(" where id in (" + idlist + ")  ");
            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PreeRegisterModel.hars_appointmentrecord GetModel(int id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,mtype,name,tel,card,gender,addr,birth,ctype,cid,ptype,rtype,deptid,deptname,doctorid,doctorname,wid,iid,inum,oid,ofee,price,price2,cout,dcount,tdate,isdelete,createdate,lastdate from hars_appointmentrecord ");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            PreeRegisterModel.hars_appointmentrecord model = new PreeRegisterModel.hars_appointmentrecord();
            DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PreeRegisterModel.hars_appointmentrecord DataRowToModel(DataRow row)
        {
            PreeRegisterModel.hars_appointmentrecord model = new PreeRegisterModel.hars_appointmentrecord();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["mtype"] != null && row["mtype"].ToString() != "")
                {
                    model.mtype = int.Parse(row["mtype"].ToString());
                }
                if (row["name"] != null)
                {
                    model.name = row["name"].ToString();
                }
                if (row["tel"] != null)
                {
                    model.tel = row["tel"].ToString();
                }
                if (row["card"] != null)
                {
                    model.card = row["card"].ToString();
                }
                if (row["gender"] != null && row["gender"].ToString() != "")
                {
                    model.gender = int.Parse(row["gender"].ToString());
                }
                if (row["addr"] != null)
                {
                    model.addr = row["addr"].ToString();
                }
                if (row["birth"] != null)
                {
                    model.birth = row["birth"].ToString();
                }
                if (row["ctype"] != null && row["ctype"].ToString() != "")
                {
                    model.ctype = int.Parse(row["ctype"].ToString());
                }
                if (row["cid"] != null)
                {
                    model.cid = row["cid"].ToString();
                }
                if (row["ptype"] != null && row["ptype"].ToString() != "")
                {
                    model.ptype = int.Parse(row["ptype"].ToString());
                }
                if (row["rtype"] != null && row["rtype"].ToString() != "")
                {
                    model.rtype = int.Parse(row["rtype"].ToString());
                }
                if (row["deptid"] != null)
                {
                    model.deptid = row["deptid"].ToString();
                }
                if (row["deptname"] != null)
                {
                    model.deptname = row["deptname"].ToString();
                }
                if (row["doctorid"] != null)
                {
                    model.doctorid = row["doctorid"].ToString();
                }
                if (row["doctorname"] != null)
                {
                    model.doctorname = row["doctorname"].ToString();
                }
                if (row["wid"] != null)
                {
                    model.wid = row["wid"].ToString();
                }
                if (row["iid"] != null)
                {
                    model.iid = row["iid"].ToString();
                }
                if (row["inum"] != null)
                {
                    model.inum = row["inum"].ToString();
                }
                if (row["oid"] != null)
                {
                    model.oid = row["oid"].ToString();
                }
                if (row["ofee"] != null && row["ofee"].ToString() != "")
                {
                    model.ofee = int.Parse(row["ofee"].ToString());
                }
                if (row["price"] != null && row["price"].ToString() != "")
                {
                    model.price = int.Parse(row["price"].ToString());
                }
                if (row["price2"] != null && row["price2"].ToString() != "")
                {
                    model.price2 = int.Parse(row["price2"].ToString());
                }
                if (row["cout"] != null && row["cout"].ToString() != "")
                {
                    model.cout = int.Parse(row["cout"].ToString());
                }
                if (row["dcount"] != null && row["dcount"].ToString() != "")
                {
                    model.dcount = int.Parse(row["dcount"].ToString());
                }
                if (row["tdate"] != null)
                {
                    model.tdate = row["tdate"].ToString();
                }
                if (row["isdelete"] != null && row["isdelete"].ToString() != "")
                {
                    model.isdelete = int.Parse(row["isdelete"].ToString());
                }
                if (row["createdate"] != null && row["createdate"].ToString() != "")
                {
                    model.createdate = DateTime.Parse(row["createdate"].ToString());
                }
                if (row["lastdate"] != null && row["lastdate"].ToString() != "")
                {
                    model.lastdate = DateTime.Parse(row["lastdate"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,state,mtype,name,tel,card,gender,addr,birth,ctype,cid,ptype,rtype,deptid,deptname,doctorid,doctorname,wid,iid,inum,oid,ofee,price,price2,cout,dcount,tdate,isdelete,createdate,lastdate ");
            strSql.Append(" FROM hars_appointmentrecord ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by id desc ");
            return DbHelperMySQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM hars_appointmentrecord ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperMySQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.id desc");
            }
            strSql.Append(")AS Row, T.*  from hars_appointmentrecord T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperMySQL.Query(strSql.ToString());
        }

        /*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "hars_appointmentrecord";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        public bool Update(string state, string oid, string iid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update hars_appointmentrecord set ");
            strSql.Append("state=@state,");
            strSql.Append("lastdate=@lastdate");
            strSql.Append(" where oid=@oid and iid=@iid");
            MySqlParameter[] parameters = {
                    new MySqlParameter("@state", MySqlDbType.Int32,2),
                    new MySqlParameter("@lastdate", MySqlDbType.Timestamp),
                    new MySqlParameter("@oid", MySqlDbType.VarChar,50),
                    new MySqlParameter("@iid", MySqlDbType.VarChar,200)};
            parameters[0].Value = state;
            parameters[1].Value = DateTime.Now;
            parameters[2].Value = oid;
            parameters[3].Value = iid;

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion  ExtensionMethod
    }
}

